import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './assets/css/global.css'
import axios from 'axios'

// axios.defaults.baseURL = 'http://localhost:8888/apis/' 因为在vue.config.js中配置跨域访问所以这里不再需要设置base url
axios.interceptors.request.use(config => {
  config.headers.token = window.sessionStorage.getItem('token')
  return config
})
axios.interceptors.response.use(config => {
  console.log("response", config)
  if (config.status == 200) {

    if (config.data.code === 401) return router.replace({
      path: '/login'
    })
    else if (config.data.code === 1) {
      console.log("请求异常", config)
    }
  } else {
    console.log("后台异常")
  }

  return config
})
Vue.prototype.$http = axios
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
